<?php
require('config.php');

        $phone=$_REQUEST['phone'];
        $content=$_REQUEST['content'];
        $user_id=$_REQUEST['user_id'];
        $shopId=$_REQUEST['shopId'];
        $orderId=$_REQUEST['orderId'];
        $time=time();
        //$time=date('Y-m-d H:i:s');
        	$sql="select * from `".$oto."_complain` where shopId='{$shopId}' and `userId`='{$user_id}' and isFlag='1'";
			$result=$db->query($sql);
			while($row=$result->fetch_assoc()){
				$suggest[]=$row;//将取得的所有数据赋值给person_info数组
			}
			if(isset($suggest))
			{
				$data[0]['pan']="-1";
				$data[0]['msg']="您已经投诉过了";
			}
			else
			{
				$sql="INSERT INTO ".$oto."_complain (`userId`,`phone`,`content`,`orderId`,`shopId`,`time`) VALUES ('$user_id','$phone','$content','$orderId','$shopId','$time')";
				//file_put_contents("tsxx.txt", "\r\n".$sql."\r\n", FILE_APPEND);
	        	$result=$db->query($sql);
	        	if($result)
	        	{
	        		$data[0]['pan']="1";
	        		$data[0]['msg']="投诉成功";
	        	}
	        	else
	        	{
	        		$data[0]['pan']="-1";
	        		$data[0]['msg']="投诉失败";
	        	}
			}
        echo json_encode($data);
?>